from selenium import webdriver
import time
from selenium.webdriver.support.wait import WebDriverWait


class TestOnlineLoans:

    # def test_onlineLoans1(self):
    #     driver = webdriver.Chrome()
    #
    #     driver.get(url='http://localhost:90/')
    #
    #     driver.maximize_window()
    #
    #     driver.find_element_by_xpath('//input[@id="username"]').send_keys("lisi")
    #
    #     driver.find_element_by_xpath('//input[@id="password"]').send_keys("123456")
    #
    #     driver.find_element_by_xpath('//button[@id="login_btn"]').click()
    #     # 登录操作
    #     time.sleep(1)
    #
    #     # /html/body/div[1]/div/main/div/div/div/div/div[2]/div[2]/div[2]/div/button[6]/span
    #
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[4]/a').click()
    #     # 点击个人中心
    #     time.sleep(1)
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[4]/ul/li[2]').click()
    #     # 点击我的借贷
    #     time.sleep(1)
    #     text1 = driver.find_element_by_xpath('/html/body/div[1]/div/main/div/div/div/div/div[2]/div[2]/div[2]/div/button[6]/span').text
    #     # 借贷信息条数
    #
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/a').click()
    #     # 点击金融工具
    #     time.sleep(1)
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/ul/li[2]').click()
    #     # 点击安全网贷
    #     time.sleep(1)
    #     driver.find_element_by_xpath("//input[@id='amount']").send_keys("10000")
    #     # 输入借贷金额 10000
    #
    #     driver.find_element_by_xpath("//input[@id='term']").send_keys('10')
    #     # 借贷期限输入 10
    #
    #     driver.find_element_by_xpath("//button[@id='submit']").click()
    #     # 点击申请按钮
    #
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath("//div[@class='jconfirm-buttons']/button[1]").click()
    #     # 点击确认按钮
    #     time.sleep(3)
    #
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[4]/a').click()
    #     # 点击个人中心
    #     time.sleep(1)
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[4]/ul/li[2]').click()
    #     # 点击我的借贷
    #     time.sleep(1)
    #     text2 = driver.find_element_by_xpath(
    #         '/html/body/div[1]/div/main/div/div/div/div/div[2]/div[2]/div[2]/div/button[6]/span').text
    #     # 借贷信息条数
    #
    #     index1 = text1.find('条')
    #     index2 = text2.find('条')
    #     info1 = text1[:index1]
    #     info2 = text2[:index2]
    #
    #     if int(info1) + 1 == int(info2):
    #         print('通过')
    #     else:
    #         print('不通过')
    #
    #     assert int(info1) + 1 == int(info2)
    #
    #     driver.quit()

    # def test_onlineLoans2(self):
    #
    #     driver = webdriver.Chrome()
    #
    #     driver.get(url='http://localhost:90/')
    #
    #     driver.maximize_window()
    #
    #     driver.find_element_by_xpath('//input[@id="username"]').send_keys("lisi")
    #
    #     driver.find_element_by_xpath('//input[@id="password"]').send_keys("123456")
    #
    #     driver.find_element_by_xpath('//button[@id="login_btn"]').click()
    #     # 登录操作
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/a').click()
    #     # 点击金融工具
    #     time.sleep(1)
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/ul/li[2]').click()
    #     # 点击安全网贷
    #     time.sleep(1)
    #     driver.find_element_by_xpath("//input[@id='amount']").send_keys("10000")
    #     # 输入借贷金额 10000
    #
    #     driver.find_element_by_xpath("//input[@id='term']").send_keys('10')
    #     # 借贷期限输入 10
    #
    #     driver.find_element_by_xpath("//button[@id='submit']").click()
    #     # 点击申请按钮
    #
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath("//div[@class='jconfirm-buttons']/button[1]").click()
    #     # 点击确认按钮
    #     time.sleep(3)
    #
    #
    #     # 银行端操作
    #     driver2 = webdriver.Chrome()
    #
    #     driver2.get(url='http://localhost:90/')
    #
    #     driver2.maximize_window()
    #
    #     driver2.find_element_by_xpath('//input[@id="username"]').send_keys("admin")
    #
    #     driver2.find_element_by_xpath('//input[@id="password"]').send_keys("123456")
    #
    #     driver2.find_element_by_xpath('//button[@id="login_btn"]').click()
    #     # 登录操作
    #     time.sleep(1)
    #
    #     driver2.find_element_by_xpath("//nav[@class='sidebar-main']/ul/li[5]/a").click()
    #     # 点击网贷管理
    #     time.sleep(1)
    #     driver2.find_element_by_xpath("//nav[@class='sidebar-main']/ul/li[5]/ul/li[1]/a").click()
    #     # 选择网贷审核
    #     time.sleep(1)
    #
    #     driver2.find_element_by_xpath("//nav[contains(@aria-label,'Page')]/ul/li[last()]/a").click()
    #     # 点击末页按钮
    #     time.sleep(2)
    #
    #     driver2.find_element_by_xpath("//div[@class='card-body']/div/table/tbody/tr[last()]/td[last()]/button[1]").click()
    #     # 点击 审核通过 按钮
    #     time.sleep(2)
    #     driver2.find_element_by_xpath("//div[@class='jconfirm-buttons']/button[1]").click()
    #     # 点击确认按钮
    #     time.sleep(2)
    #
    #     driver2.quit()
    #
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[4]/a').click()
    #     # 点击个人中心
    #     time.sleep(1)
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[4]/ul/li[3]').click()
    #     # 点击 银行卡管理
    #     time.sleep(1)
    #
    #     text2 = driver.find_element_by_xpath("//div[@class='row']/div[not(@class)]/div/div/div[contains(@class,'card-body')]/h4[2]").text
    #     # 当前默认银行卡的 余额数
    #     start = text2.find('：')
    #     end = text2.rfind('元')
    #     info2 = text2[start+1:end]
    #
    #     if info2 == '20000.00':
    #         print('通过')
    #     else:
    #         print('不通过')
    #
    #     assert info2 == '20000.00'
    #
    #     driver.quit()

    # def test_onlineLoans3(self):
    #     driver = webdriver.Chrome()
    #
    #     driver.get(url='http://localhost:90/')
    #
    #     driver.maximize_window()
    #
    #     driver.find_element_by_xpath('//input[@id="username"]').send_keys("lisi5")
    #
    #     driver.find_element_by_xpath('//input[@id="password"]').send_keys("123456")
    #
    #     driver.find_element_by_xpath('//button[@id="login_btn"]').click()
    #     # 登录操作
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/a').click()
    #     # 点击金融工具
    #     time.sleep(1)
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/ul/li[2]').click()
    #     # 点击安全网贷
    #     time.sleep(1)
    #     driver.find_element_by_xpath("//input[@id='amount']").send_keys("10000")
    #     # 输入借贷金额 10000
    #
    #     driver.find_element_by_xpath("//input[@id='term']").send_keys('10')
    #     # 借贷期限输入 10
    #
    #     driver.find_element_by_xpath("//button[@id='submit']").click()
    #     # 点击申请按钮
    #
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath("//div[@class='jconfirm-buttons']/button[1]").click()
    #     # 点击确认按钮
    #     time.sleep(3)
    #
    #     result = driver.find_element_by_xpath("//div[@class='jconfirm-content']/div").text
    #
    #     if result == '申请失败!,请先绑定银行卡':
    #         print('通过')
    #     else:
    #         print('不通过')
    #
    #     assert result == '申请失败!,请先绑定银行卡'
    #
    #     driver.quit()

    # def test_onlineLoans4(self):
    #     driver = webdriver.Chrome()
    #
    #     driver.get(url='http://localhost:90/')
    #
    #     driver.maximize_window()
    #
    #     driver.find_element_by_xpath('//input[@id="username"]').send_keys("lisi")
    #
    #     driver.find_element_by_xpath('//input[@id="password"]').send_keys("123456")
    #
    #     driver.find_element_by_xpath('//button[@id="login_btn"]').click()
    #     # 登录操作
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/a').click()
    #     # 点击金融工具
    #     time.sleep(1)
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/ul/li[2]').click()
    #     # 点击安全网贷
    #     time.sleep(1)
    #     driver.find_element_by_xpath("//input[@id='amount']").send_keys("100000000000000000")
    #     # 输入借贷金额 100000000000000000
    #
    #     driver.find_element_by_xpath("//input[@id='term']").send_keys('10')
    #     # 借贷期限输入 10
    #
    #     driver.find_element_by_xpath("//button[@id='submit']").click()
    #     # 点击申请按钮
    #
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath("//div[@class='jconfirm-buttons']/button[1]").click()
    #     # 点击确认按钮
    #     time.sleep(3)
    #
    #     result = driver.find_element_by_xpath("//div[@class='jconfirm-content']/div").text
    #
    #     if result == '申请失败':
    #         print('通过')
    #     else:
    #         print('不通过')
    #
    #     assert result == '申请失败'
    #
    #     driver.quit()

    # def test_onlineLoans5(self):
    #     driver = webdriver.Chrome()
    #
    #     driver.get(url='http://localhost:90/')
    #
    #     driver.maximize_window()
    #
    #     driver.find_element_by_xpath('//input[@id="username"]').send_keys("lisi")
    #
    #     driver.find_element_by_xpath('//input[@id="password"]').send_keys("123456")
    #
    #     driver.find_element_by_xpath('//button[@id="login_btn"]').click()
    #     # 登录操作
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/a').click()
    #     # 点击金融工具
    #     time.sleep(1)
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/ul/li[2]').click()
    #     # 点击安全网贷
    #     time.sleep(1)
    #     driver.find_element_by_xpath("//input[@id='amount']").send_keys("10")
    #     # 输入借贷金额 10
    #
    #     driver.find_element_by_xpath("//input[@id='term']").send_keys('10')
    #     # 借贷期限输入 10
    #
    #     driver.find_element_by_xpath("//button[@id='submit']").click()
    #     # 点击申请按钮
    #
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath("//div[@class='jconfirm-buttons']/button[1]").click()
    #     # 点击确认按钮
    #     time.sleep(3)
    #
    #     ele = None
    #     try:
    #         ele = driver.find_element_by_xpath("//div[@class='jconfirm-content']/div")
    #     except:
    #         pass
    #
    #     if ele and ele.text == '申请失败，申请额度必须是100的整数倍':
    #         print('通过')
    #     else:
    #         print('不通过')
    #
    #     assert ele and ele.text == '申请失败，申请额度必须是100的整数倍'
    #
    #     driver.quit()


    # def test_onlineLoans6(self):
    #     driver = webdriver.Chrome()
    #
    #     driver.get(url='http://localhost:90/')
    #
    #     driver.maximize_window()
    #
    #     driver.find_element_by_xpath('//input[@id="username"]').send_keys("lisi")
    #
    #     driver.find_element_by_xpath('//input[@id="password"]').send_keys("123456")
    #
    #     driver.find_element_by_xpath('//button[@id="login_btn"]').click()
    #     # 登录操作
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/a').click()
    #     # 点击金融工具
    #     time.sleep(1)
    #     driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/ul/li[2]').click()
    #     # 点击安全网贷
    #     time.sleep(1)
    #     driver.find_element_by_xpath("//input[@id='amount']").send_keys("100")
    #     # 输入借贷金额 100
    #
    #     driver.find_element_by_xpath("//input[@id='term']").send_keys('366')
    #     # 借贷期限输入 366
    #
    #     driver.find_element_by_xpath("//button[@id='submit']").click()
    #     # 点击申请按钮
    #
    #     time.sleep(1)
    #
    #     driver.find_element_by_xpath("//div[@class='jconfirm-buttons']/button[1]").click()
    #     # 点击确认按钮
    #     time.sleep(3)
    #
    #     ele = None
    #     try:
    #         ele = driver.find_element_by_xpath("//div[@class='jconfirm-content']/div")
    #     except:
    #         pass
    #
    #     if ele and ele.text == '输入期限不合法！':
    #         print('通过')
    #     else:
    #         print('不通过')
    #
    #     assert ele and ele.text == '输入期限不合法！'
    #
    #     driver.quit()

    def test_onlineLoans7(self):
        driver = webdriver.Chrome()

        driver.get(url='http://localhost:90/')

        driver.maximize_window()

        driver.find_element_by_xpath('//input[@id="username"]').send_keys("lisi")

        driver.find_element_by_xpath('//input[@id="password"]').send_keys("123456")

        driver.find_element_by_xpath('//button[@id="login_btn"]').click()
        # 登录操作
        time.sleep(1)

        driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/a').click()
        # 点击金融工具
        time.sleep(1)
        driver.find_element_by_xpath('//nav[@class="sidebar-main"]/ul/li[3]/ul/li[2]').click()
        # 点击安全网贷
        time.sleep(1)
        driver.find_element_by_xpath("//input[@id='amount']").send_keys("100")
        # 输入借贷金额 100

        driver.find_element_by_xpath("//input[@id='term']").send_keys('365')
        # 借贷期限输入 366

        driver.find_element_by_xpath("//button[@id='submit']").click()
        # 点击申请按钮

        time.sleep(1)

        driver.find_element_by_xpath("//div[@class='jconfirm-buttons']/button[1]").click()
        # 点击确认按钮
        ele = driver.find_element_by_xpath("//div[@class='jconfirm-content']/div")
        text2 = ele.text

        if text2 == '申请成功!请等待管理员审核':
            print('通过')
        else:
            print('不通过！')

        assert text2 == '申请成功!请等待管理员审核'

        driver.quit()